/*
 *  作业2
 */
package com.stage_1.module_4;

import java.io.FileWriter;
import java.io.IOException;
import java.util.*;


public class FileTest {
    public static void main(String[] args){
        FileWriter fw = null;
        try {
            //指定文件
            fw = new FileWriter("abc.txt");

            //接收输入的字符串
            List<String> ss = new ArrayList<>();

            Scanner sc = new Scanner(System.in);
            while (true){
                String s = sc.next();
                if (s.equals("end")) break;
                ss.add(s);
            }

            //按字典顺序倒序排序
            Collections.sort(ss);
            Collections.reverse(ss);
            System.out.println(ss);

            //写入文件
            for (String i : ss){
                fw.write(i);
                fw.write("\n");
            }


            System.out.println("写入成功！");

            fw.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
